package com.yedean.factory.context;

import com.yedean.factory.BeansException;
import com.yedean.factory.ConfigurableListableBeanFactory;
import com.yedean.factory.support.DefaultListableBeanFactory;

/**
 * @author HUAWEI
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext{
    
    private DefaultListableBeanFactory beanFactory;

    

    @Override
    protected void refreshBeanFactory() throws BeansException {
        //1.创建bean工厂
        DefaultListableBeanFactory beanFactory =createBeanFactory();
        //把bean工厂当参数穿进去给下层实现类使用加载定义
        loadBeanDefinitions(beanFactory);
        this.beanFactory=beanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory();
    }
    
    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory factory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
